/**
 * Created by billy on 2020/12/21.
 */
var cmdBase = require("./cmd-base");

var argv = {
	name: "",
	param: [],
	options: {}
}

var argvList = getArgs();

var hasTime = false;
var timeIndex = 0;

for (var i = 0; i < argvList.length; i++)
{
	if (hasTime)
	{
		argvList[timeIndex] += " " + argvList[i];
		var lastChar = argvList[i].charAt(argvList[i].length - 1);
		if (lastChar == "]" || lastChar == ")")
		{
			hasTime = false;
		}
		argvList.splice(i, 1);
		i--;
	}
	else if (argvList[i].indexOf("--time") == 0)
	{
		timeIndex = i;
		hasTime = true;
	}
}

for (var item of argvList)
{
	if (item.indexOf("--") == 0)
	{
		var itemArr = item.split("=");
		var itemName = itemArr[0].replace("--", "");
		var itemVal = itemArr[1];
		isNum(itemVal) && (itemVal = Number(itemVal));
		if (itemName == "file")
		{
			argv.name = itemVal;
		}
		else
		{
			argv.options[itemName] = itemVal || true;
		}
	}
	else
	{
		if (!argv.name)
		{
			argv.name = item;
		}
		else
		{
			isNum(item) && (item = Number(item));
			argv.param.push(item);
		}
	}
}

cmdBase.checkAndStart(argv);

module.exports = argv;